<template>
  <div class='settings first-box'>
    <Form :formData="formData" :formParam="formParam" ></Form>
    <Btn class="margin40" :buttonData="buttonData"></Btn>
  </div>
</template>
<script>
import Form from '../../common/form'
import Btn from '../../common/button.vue'
export default {
  components: {Form,Btn},
  name: "",
  data() {
    return {
      formData:[
        {
          title:{
            show:true,
            img:require("../../../assets/img/vip/settings/info.png"),
            label:"基本信息"
          },
          children:[
            {type:"input",label:"姓名",key:"realName",},
            {type:"radio",label:"性别：",key:"sex",array:[{label:"男",key:"1"},{label:"女",key:"0"}],sex:true},
            {type:"date",label:"出生日期",key:"birthday",},
            {type:"number",label:"手机号",key:"phone",},
          ],
        },{
          title:{
            show:true,
            img:require("../../../assets/img/vip/settings/car.png"),
            label:"车辆信息"
          },
          children:[
            {type:"input",label:"车型",key:"carModel",array:[]},
            {type:"input",label:"车牌号",key:"plateNum",},
            {type:"number",label:"车架号码",key:"frameNum",otherText:"后6位"},
            {type:"number",label:"发动机号",key:"engineNum",otherText:"后6位"},
          ],
        },{
          title:{
            show:false,
          },
          children:[
            {type:"date",label:"保险购买日期",key:"insuranceStarts",},
            {type:"number",label:"上次保养公里数",key:"lastMaintainKm",unit:"公里"},
            {type:"date",label:"上次保养时间",key:"lastMaintainTimes",},
          ],
        },{
          title:{
            show:false,
          },
          children:[
            {type:"date",label:"首次上牌时间",key:"firstBoardTimes",},
          ],
        }
      ],
      formParam:{
        realName:"",
        sex:"",
        birthday:"2018-5-5",
        phone:"",
        carModel:"",
        plateNum:"",
        frameNum:"",
        engineNum:"",
        insuranceStarts:"",
        lastMaintainKm:"",
        lastMaintainTimes:"",
        firstBoardTimes:"",
      },

      buttonData:[
        {
          label:"保存",
          click:this.save
        }
      ]
    };
  },
  methods: {
    save(){
      var params={
        // userId:sessionStorage.getItem("userId")
      }
      
      var params=JSON.parse(JSON.stringify(this.formParam))
      // if(params.sex.value){

      // }

      _g.apiPost("vipPage/saveMessage.do",params).then(res=>{
        _g.toMessage(res)
      })
      // console.log("click---保存设置")
    },
    getList(){
      var params={
        // userId:sessionStorage.getItem("userId")
      }
      _g.apiPost("vipPage/setMessage.do",params).then(res=>{
        this.formParam.realName=res.data.user.realName
        this.formParam.sex=res.data.user.sex
        this.formParam.birthday=res.data.user.birthday
        this.formParam.phone=res.data.user.phone
        this.formParam.carModel=res.data.vehicle.carModel||""
        this.formParam.plateNum=res.data.vehicle.plateNum||""
        this.formParam.frameNum=res.data.vehicle.frameNum||""
        this.formParam.engineNum=res.data.vehicle.engineNum||""
        this.formParam.insuranceStarts=res.data.vehicle.insuranceStarts?_g.formatTime(res.data.vehicle.insuranceStarts):""
        this.formParam.lastMaintainKm=res.data.vehicle.lastMaintainKm||""
        this.formParam.lastMaintainTimes=res.data.vehicle.lastMaintainTimes?_g.formatTime(res.data.vehicle.lastMaintainTimes):""
        this.formParam.firstBoardTimes=res.data.vehicle.firstBoardTimes?_g.formatTime(res.data.vehicle.firstBoardTimes):""
        this.formParam.vehicleId=res.data.vehicle.id||""
      })
    }
  },
  created() {
    this.getList()
  }
};
</script>
<style lang="scss" scoped>
.settings {

  .margin40{
    margin: 40px 30px;
  }
}
</style>